//
//  AssetViewCell.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/5/4.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit
protocol AssetCollecCellDelegate:class {
    func sendCoin()
    func receive()
}
class AssetViewCell: BaseCollectionViewCell {
    weak var delegate:AssetCollecCellDelegate?
    lazy var imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.isUserInteractionEnabled = true
        return imageView
    }()
    
    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = UIColor(hexStr: "#ead6f8")
        return label
    }()
    
    lazy var kindLabel:UILabel = {
        let label = UILabel()
        label.textAlignment = .center
        label.adjustsFontSizeToFitWidth = true
        label.font = UIFont.systemFont(ofSize: 20)
        label.textColor = UIColor(hexStr: "#e7ebf4")
//        label.text = "估值 0.5671 BTC"
        return label
    }()
    
    lazy var moneyLabel:UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        label.textColor = UIColor(hexStr: "#be97d9")
//        label.text = "≈ 3456.45 CNY"
        return label
    }()
    
    lazy var horiLine: UIView = {
        let view = UIView()
        return view
    }()
    
    lazy var verLine: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hexStr: "#8b41bd")
        return view
    }()
    lazy var sendBtn: CustomBtn = {
        let btn = CustomBtn(style: .styleRight)
//        btn.nameLabel.text = "发送"
        btn.addTarget(self, action: #selector(sendBtnAction), for: UIControlEvents.touchUpInside)
        btn.nameLabel.textColor = UIColor(hexStr: "#efe7f4")
        btn.nameLabel.font = UIFont.systemFont(ofSize: 14)
        btn.photoImageView.image = UIImage(named: "assetSend")
        return btn
    }()
    
    lazy var receiveBtn: CustomBtn = {
        let btn = CustomBtn(style: .styleRight)
//        btn.nameLabel.text = "接收"
        btn.addTarget(self, action: #selector(receiveAction), for: UIControlEvents.touchUpInside)
        btn.nameLabel.textColor = UIColor(hexStr: "#efe7f4")
        btn.nameLabel.font = UIFont.systemFont(ofSize: 14)
        return btn
    }()
    
    override func setUpUI() {
        self.contentView.addSubview(imageView)
        imageView.snp.makeConstraints { (make) in
            make.top.bottom.left.right.equalToSuperview()
        }
        
        imageView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(27)
            make.centerX.equalToSuperview()
        }
        
        imageView.addSubview(kindLabel)
        kindLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(54)
            make.left.equalTo(imageView).offset(8)
            make.right.equalTo(imageView).offset(-8)
        }
        
        imageView.addSubview(moneyLabel)
        moneyLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(88)
            make.centerX.equalToSuperview()
        }
        
        imageView.addSubview(horiLine)
        horiLine.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(118)
            make.left.right.equalToSuperview()
            make.height.equalTo(0.5)
        }
        
        imageView.addSubview(verLine)
        verLine.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-16)
            make.width.equalTo(0.5)
            make.height.equalTo(14)
        }
        imageView.addSubview(sendBtn)
        sendBtn.position?.exchangePlace(btn: sendBtn)
        sendBtn.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview()
            make.left.equalToSuperview()
            make.width.equalTo((kSCREEN_WIDTH-46)/2)
            make.height.equalTo(45)
        }

        
        imageView.addSubview(receiveBtn)
        receiveBtn.position?.exchangePlace(btn: receiveBtn)
        receiveBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview()
            make.bottom.equalToSuperview()
            make.width.equalTo((kSCREEN_WIDTH-46)/2)
            make.height.equalTo(45)
        }
    }
    
    @objc func sendBtnAction() {
        if delegate != nil {
            self.delegate!.sendCoin()
        }
    
    }
    @objc func receiveAction() {
        if delegate != nil {
            self.delegate!.receive()
        }
    }
}
